home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / test / testinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  1.4 KB  |  83 lines

  1. /*
  2.  * testinit.c --
  3.  *    Standard stand alone C code test driver.
  4.  *
  5.  * Note:
  6.  *    Just create TestMain() in a separate file and link.
  7.  */
  8.  
  9. #ifndef lint
  10. static    char
  11.     testinit_c[] = "$Header: /private/postgres/src/test/RCS/testinit.c,v 1.6 1990/02/12 19:52:03 cimarron Version_2 $";
  12. #endif    /* !defined(lint) */
  13.  
  14. #include <signal.h>
  15. #include <stdio.h>
  16. #include <setjmp.h>
  17. #include <strings.h>
  18. #include "log.h"
  19. #include "bufmgr.h"
  20. #include "xcxt.h"
  21.  
  22. extern void    TestMain();
  23.  
  24. static    char    Buf[MAXPGPATH];
  25. jmp_buf    Warn_restart;
  26.  
  27. handle_warn()
  28. {
  29.     extern    jmp_buf    Warn_restart;
  30.  
  31.     longjmp(Warn_restart);
  32. }
  33.  
  34. /* exit gracefully */
  35. die()
  36. {
  37.     exitpg(0);
  38. }
  39.  
  40. main(argc, argv)
  41. int    argc;
  42. char    *argv[];
  43. {
  44.     char        *datname;
  45.     extern    jmp_buf    Warn_restart;
  46.     int        geteuid(), setuid();            /* uid_t */
  47.     int        chdir(), setjmp(), fprintf();
  48.     char        *getenv();
  49.     extern        exitpg();
  50.     extern        resetmmgr();
  51.  
  52.     if (argc > 2) {
  53.         fprintf(stderr, "Usage: %s [datname]\n", rindex(argv[0], '/') ?
  54.             rindex(argv[0], '/') + 1 : argv[0]);
  55.         exitpg(1);
  56.     }
  57.     if (argc == 2)
  58.         datname = argv[1];
  59.     else if ((datname = getenv("USER")) == (char *)NULL) {
  60.         fprintf(stderr, "failed getenv(\"USER\")");
  61.         exitpg(1);
  62.     }
  63.  
  64.     signal(SIGHUP, die);
  65.     signal(SIGINT, die);
  66.     signal(SIGTERM, die);
  67.  
  68.     InitPostgres(Buf, datname);
  69.  
  70.     if (chdir(Buf) < 0) {
  71.             elog(FATAL, "chdir(\"%s\"): %m", Buf);
  72.     }
  73.  
  74.     setuid(geteuid());
  75.     signal(SIGHUP, handle_warn);
  76.  
  77.     if (setjmp(Warn_restart) != NULL) {
  78.         AbortCurrentTransaction();
  79.     }
  80.  
  81.     TestMain();
  82. }
  83.